package com.corpdata.app.project.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.corpdata.app.project.entity.ProjectField;
import com.corpdata.app.project.service.ProjectFieldService;
import com.corpdata.app.project.service.ProjectSetService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.common.upload.service.SysAttachmentService;
import com.corpdata.common.utils.CorpdataUtil;
import com.corpdata.system.log.OptLog;
import com.corpdata.system.log.OptLogConstant;
import com.corpdata.system.log.WebLog;
import com.corpdata.core.base.BaseController;

/**
 * 分店场地
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-07-16 11:00:04
 */
 
@Controller
@RequestMapping("app/projectField")
public class ProjectFieldController extends BaseController{

	@Autowired
	private ProjectFieldService projectFieldService;
	
	@Autowired
	private ProjectSetService projectSetService;
	
	@Autowired
	private SysAttachmentService sysAttachmentService;
	
	
	//首页页面
	@GetMapping("/index")
	public String index(){
		return "app/project/field/field_index";
	}
	
		
	//新增页面
	@GetMapping("/add/{id}")
	public String add(@PathVariable("id") String id,ModelMap map){
		map.put("projectId", id);
		map.put("id", CorpdataUtil.getUUID());
		return "app/project/field/field_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	@OptLog(info=OptLogConstant.INFO_ADD+"场地",module="场地")
	public Result save(ProjectField record,String fileId){
		return projectFieldService.insert(record,fileId);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", projectFieldService.findById(id));
		map.put("sysa", sysAttachmentService.findByDocUnid(id));
		return "app/project/field/field_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	@OptLog(info=OptLogConstant.INFO_MOF+"场地",module="场地")
	public Result update(ProjectField record,String fileId){
		return projectFieldService.update(record,fileId);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	@OptLog(info=OptLogConstant.INFO_DEL+"场地",module="场地")
	public Result delete(String id){
		return projectFieldService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return projectFieldService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}_{projectId}")
	public String details(ModelMap map,@PathVariable("id") String id,@PathVariable("projectId") String projectId){
		map.put("record", projectFieldService.findById(id));
		map.put("set", projectSetService.findById(projectId));
	    return "app/project/field/field_details";
	}
	
	//列表页面
	@GetMapping("/list")
	public String list(){
	    return "app/project/field/field_list";
	}
	
	//预约管理页面
	@GetMapping("/orderManage/{projectId}")
	public String orderManage(ModelMap map,@PathVariable("projectId") String projectId){
		map.put("set", projectSetService.findById(projectId));
	    return "app/project/field/field_orderManage";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return projectFieldService.findByPage(dgRequest);
	}
	
	@ResponseBody
	@RequestMapping("/selectjson/{id}")
	public String getSelectJsonData(@PathVariable("id") String id){
		return projectFieldService.selectAllByCombox(id);
	}
	
}
